#include "Board.h"

Board::Board(void)
{
	//Points for board construction
	leftCurvePoints = new vector3[t_count];
	rightCurvePoints = new vector3[t_count];
	_points = new vector3[total_points]; 
	init();
}


Board::~Board(void)
{
	//delete _points;
	//delete leftCurvePoints;
	//delete rightCurvePoints;
}

void Board::init( void )
{
	//Points for board construction
	leftCurvePoints = new vector3[t_count];
	rightCurvePoints = new vector3[t_count];
	_points = new vector3[total_points]; 

	//topleft beizier curve
	generateBezierCurve( vector3( LEFT_X, TOP_Y * .60, 0),
						 TOP_LEFT_POINT,
						 TOP_LEFT_POINT,
						 vector3( RIGHT_X -((RIGHT_X - LEFT_X) / 2), TOP_Y, 0 ), 
						 leftCurvePoints);
	//topright beizier curve
	generateBezierCurve( vector3( RIGHT_X -((RIGHT_X - LEFT_X) / 2), TOP_Y, 0 ),
						 TOP_RIGHT_POINT,
						 TOP_RIGHT_POINT,
						 vector3( RIGHT_X, TOP_Y * .60, 0),
						 rightCurvePoints);

	//build rest of points for the table
	for( int i = 0; i < count;i++){
		_points[i] = leftCurvePoints[i];
		_points[i+100] = rightCurvePoints[i];
	}

	_points[total_points-5] = BOTTOM_RIGHT_POINT;
	_points[total_points-4] = BOTTOM_LEFT_POINT;
	_points[total_points-3] = BOTTOM_LEFT_POINT;
	_points[total_points-2] = leftCurvePoints[0];
	_points[total_points-1] = leftCurvePoints[0];

	_bgColor = COLOR( .5, .5, .5 );
	_boarderColor = GREEN;

}

void Board::drawMe()
{
	DrawTools::drawCircle( BOTTOM_RIGHT_POINT, 3, WHITE);
	//Game Board Boarder
	DrawTools::drawCurvePoints( _points, total_points, _boarderColor, 3 );
	//Game Board Back Face
	DrawTools::drawPolyGon(  _points, total_points, _bgColor );
}

vector3 Board::getBackColor( void )
{
	return _bgColor;
}
vector3 Board::getBoarderColor( void )
{
	return _boarderColor;
}
void Board::setColors( vector3 back, vector3 boarder )
{
	_bgColor = back;
	_boarderColor = boarder;
}

bool Board::isBallinsideBoard( Ball * ball )
{
	vector3 ball_loc = ball->transform.position;
	double radius = ball->radius;

	 //region one below bezier
	if( LEFT_X + radius <= ball_loc.getX() && ball_loc.getX() + radius <= RIGHT_X ){
		if( TOP_Y * .6 >= ball_loc.getY() + radius && ball_loc.getY() > BOTTOM_Y + radius){
			_bgColor = COLOR( .5, .5, .5 );
			return true;
		}else{
			_bgColor = RED;
		}
	}else{
		_bgColor = RED;
	}

	//region two above beizer

	return false;
}